﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using yunbo.Model.BIW;
using yunbo.Repositorys.BIWRepositorys;

namespace yunbo.Controllers.BIWControllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class Wbd_ckController : ControllerBase
    {
        Wbd_ckRepository wbd_CkRepository = new Wbd_ckRepository();

        [HttpGet("GetFYwbd_Ck")]
        public IActionResult GetFYwbd_Ck(int PageNumber, int PageSize)
        {
            FYwbd_ck fYwbd_Ck = wbd_CkRepository.GetFYwbd_Ck(PageNumber, PageSize);
            return Ok(fYwbd_Ck);
        }
        [HttpGet("Wbd_Ck")]
        public IActionResult Wbd_Ck()
        {
            List<Wbd_ck> wbd_Cks = wbd_CkRepository.Wbd_Ck();
            return Ok(wbd_Cks);
        }
        [HttpPost("AddWbd_Ck")]
        public IActionResult AddWdb_ck(TJWbd_ck wbd_Ck)
        {
            // 获取当前时间，并格式化为字符串
            string currentTime = DateTime.Now.ToString("yyyyMMdd");

            // 生成一个四位随机数
            Random random = new Random();
            int randomNumber = random.Next(1000, 10000); // 生成1000到9999之间的随机数
            string randomNumberString = randomNumber.ToString("D4"); // 格式化为四位数字字符串

            // 组合当前时间和随机数生成ID
            string code = $"ck{currentTime}{randomNumberString}";
            Wbd_ck wbd_Ck1 = new Wbd_ck()
            {
                ck_code = code,
                ck_name = wbd_Ck.ck_name,
                ck_zt = 1,
                ck_kx = wbd_Ck.ck_kx,
                cl_dz = wbd_Ck.cl_dz,
                is_deleted = 1,
                bz = wbd_Ck.bz,
                ck_mj = wbd_Ck.ck_mj,
                ck_fzr = wbd_Ck.ck_fzr,
                create_by = wbd_Ck.create_by,
                create_time = DateTime.Now,
            };
            bool ck = wbd_CkRepository.AddWbd_Ck(wbd_Ck1) > 0;
            return Ok(ck);
        }
        [HttpPut("UpdateWbd_Ck")]
        public IActionResult UpdateWbd_Ck(XGWbd_ck wbd_Ck)
        {
            Wbd_ck wbd_Ck1 = new Wbd_ck()
            {
                ck_id = wbd_Ck.ck_id,
                ck_code = wbd_Ck.ck_code,
                ck_name = wbd_Ck.ck_name,
                ck_kx = wbd_Ck.ck_kx,
                cl_dz = wbd_Ck.cl_dz,
                bz = wbd_Ck.bz,
                ck_mj = wbd_Ck.ck_mj,
                ck_fzr = wbd_Ck.ck_fzr,
                update_by = wbd_Ck.update_by,
                update_time = DateTime.Now, 
            };
            bool ck = wbd_CkRepository.UpdateWbd_Ck(wbd_Ck1) > 0;
            return Ok(ck);
        }
        [HttpPut("UpIsDel")]
        public IActionResult UpIsDel(int id)
        {
            bool ck = wbd_CkRepository.UpIsDeleted(id) > 0;
            return Ok(ck);
        }
        [HttpPut("UpZt")]
        public IActionResult UpZt(int id,int zt) 
        {
           
            bool ckt=wbd_CkRepository.UpZt(id,zt) >0;
            return Ok((ckt));
        }
        [HttpGet("MHCX")]
        public IActionResult MHCX(int PageNumber, int PageSize, int? zt, string? name)
        { 
            FYwbd_ck fYwbd_Ck=wbd_CkRepository.MHCX(PageNumber, PageSize, zt, name);
            return Ok(fYwbd_Ck);
        }
        [HttpGet("GetCkbycode")]
        public IActionResult GetCkbycode(string code)
        {
            Wbd_ck wbd_Ck = wbd_CkRepository.GetCkbycode(code);
            return Ok(wbd_Ck);
        }
    }
}
